/*
 * Name: Joon Ho Cho
 * Date: 10/24/2008
 * Course: 15-437
 */
package scheduler.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;


import org.mybeans.dao.DAOException;

import scheduler.databean.User;
import scheduler.model.BookmarkDao;
import scheduler.model.Model;
import scheduler.model.UserDao;




public class ManageAction extends Action {

	private BookmarkDao bookmarkDAO;
	private UserDao userDao;
	

	public ManageAction(Model model) {
    	bookmarkDAO = model.getBookmarkDao();
    	userDao = model.getUserDao();
	}

	public String getName() { return "manage.do"; }

	public String perform(HttpServletRequest request) {
        // Set up the errors list
        List<String> errors = new ArrayList<String>();
        request.setAttribute("errors",errors);
        
		try {
			User user = (User) request.getSession().getAttribute("user");
	        request.setAttribute("bookmarks", null);
	        request.setAttribute("bookmarks", bookmarkDAO.getBookmarksForUser(user.getUserName()));

			request.setAttribute("registeredUsers", userDao.getAll());
	        return "manage.jsp";
        } catch (DAOException e) {
        	errors.add(e.getMessage());
        	return "db-error.jsp";
        }
    }
}
